using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class LoadingView : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        GetComponentInChildren<Text>().DOText("Loading...",3).SetLoops(-1,loopType:LoopType.Restart);
    }
    public void SetActiveState(bool isShow)
    {
        gameObject.SetActive(isShow);
    }
    public void SwitchScene(string sceneName)
    {
        StartCoroutine(LoadScene(sceneName));
    }
    private IEnumerator LoadScene(string sceneName)
    {
        AsyncOperation async=SceneManager.LoadSceneAsync(sceneName);
        //场景加载好之后是否进行跳转
        async.allowSceneActivation=false;
        while(!async.isDone)
        {
            //进度，最大0.9f
            if(async.progress>=0.9f)
            {
                //模拟加载时间
                yield return new WaitForSeconds(2);
                async.allowSceneActivation=true;
            }
            yield return new WaitForSeconds(0.5f);
        }

    }
}
